import {
  caseInfoList,
  insertCaseInfo,
  caseActionList,
  caseDetail,
  editCaseInfo,
  deleteCaseInfo,
} from '@/api/register'

export default defineStore('useRegister', {
  state: () => ({}),
  getters: {},
  actions: {
    //案件列表
    async getCaseInfoList(params) {
      let url = $globalRequestUrl({
        url: caseInfoList,
      })

      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //添加案件
    async insertCaseInfo(params) {
      let url = $globalRequestUrl({
        url: insertCaseInfo,
      })

      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //案由数据
    async caseActionList(params) {
      let url = $globalRequestUrl({
        url: caseActionList,
      })

      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //案件详情
    async caseDetail(caseId) {
      let url = $globalRequestUrl({
        url: caseDetail + `/${caseId}`,
      })

      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },

    //编辑案情
    async editCaseInfo(params) {
      let url = $globalRequestUrl({
        url: editCaseInfo,
      })

      try {
        const rep = await $globalRequest(url, params, { method: 'PUT' })
        return rep
      } catch (error) {
        return error
      }
    },

    //删除案情
    async deleteCaseInfo(caseId) {
      let url = $globalRequestUrl({
        url: deleteCaseInfo + `/${caseId}`,
      })

      try {
        const rep = await $globalRequest(url, {}, { method: 'DELETE' })
        return rep
      } catch (error) {
        return error
      }
    },
  },
})
